/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.news;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.news.NewsItem;
import com.blandware.atleap.persistence.core.PageDAO;
import com.blandware.atleap.persistence.exception.DeleteException;

import java.util.Map;
import java.util.List;
import java.util.Date;

/**
 * <p>DAO for news items</p>
 * <p><a href="NewsDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.7 $ $Date: 2006/08/03 10:07:40 $
 */
public interface NewsDAO extends PageDAO {

	// ~ CRUD methods ================================================================

	/**
	 * Creates new news item
	 *
	 * @param newsItem      Value object that represents what news item must be created
	 * @param linkedObjects Map of pairs <code>uri -&gt; object<code>, which link URI in the annotation or body to
	 *                      corresponding object (resource or page) if it exists
	 * @return ID of created news item
	 */
	public Long createNewsItem(NewsItem newsItem, Map linkedObjects);

	/**
	 * Retrieves news item with specified ID
	 *
	 * @param newsItemId ID to search by
	 * @return News item with specified ID or null if no item with specified ID exists in database
	 */
	public NewsItem retrieveNewsItem(Long newsItemId);

	/**
	 * Retrieves lite version (with empty 'title', 'annotation' and 'body' maps) of news item with specified ID
	 *
	 * @param newsItemId ID to search by
	 * @return News item with specified ID or null if no item with specified ID exists in database
	 */
	public NewsItem retrieveNewsItemLite(Long newsItemId);

	/**
	 * Updates news item
	 *
	 * @param newsItem      News item to update
	 * @param linkedObjects Map of pairs <code>uri -&gt; object<code>, which link URI in the annotation or body to
	 *                      corresponding object (resource or page) if it exists
	 */
	public void updateNewsItem(NewsItem newsItem, Map linkedObjects);

	/**
	 * Deletes news item
	 *
	 * @param newsItem item to delete
	 * @throws com.blandware.atleap.persistence.exception.DeleteException
	 *          if news item cannot be deleted
	 */
	public void deleteNewsItem(NewsItem newsItem) throws DeleteException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of news items.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of news items
	 */
	public PartialCollection listNewsItems(QueryInfo queryInfo);


	/**
	 * Retrieves no more than number of elements, specified in queryInfo's <code>limit</code> field.
	 *
	 * @param queryInfo Object that contains list of user roles, number of elements to return and identifier of locale.
     * All of these are passed as query parameters: list of roles under key 'roles'
     * and identifier of locale under key 'localeIdentifier'. Only news items
     * that are allowed to view for some of the given roles are returned.
	 * @return List of news items that correspond to <code>queryInfo</code>
	 */
	public List getLastNews(QueryInfo queryInfo);

	// ~ Finders ================================================================

	/**
	 * Finds news item by URI
	 *
	 * @param newsItemUri URI of news item to search by
	 * @return News item or null if nothing was found
	 */
	public NewsItem findNewsItemByUri(String newsItemUri);

	/**
	 * Returns list of news, which are not published and are not expired at the specified date
	 * @param date Date to compare publication and expiration date to
	 * @return List of unpublished news
	 */
	public List findUnpublishedNews(Date date);

	/**
	 * Returns list of news, which are expired in comparison to specified date
	 * @param date Date to compare expiration date to
	 * @return List of expired news
	 */
	public List findExpiredNews(Date date);

}
